<template>
    <div class="login-page">
        <div class="login-header">

        </div>
        <div class="login-body">
            <div class="content-wrap">
                <div class="img-wrap">
                    <img src="../../assets/common/bg.jpeg" alt="">
                </div>
                <div class="form-wrap">
                    <div class="login-wrap" :style="{'transform': routeStep == 'register' ? 'translateX(-100%)' : 'translateX(0%)'}">
                        <div class="title">欢迎登录合作商系统</div>
                        <div class="tabs">
                            <div class="tab-item" :class="{'is-active': loginTabActive == item.value}" v-for="(item,index) in loginTabList" :key="index" @click="loginTabClick(item.value)">
                                <span>{{item.name}}</span>
                            </div>
                        </div>
                        <div class="tab-panel" v-if="loginTabActive == 1">
                           <login-by-account @submit="loginSuccess" @register="goRegister"></login-by-account>
                        </div>
                        <div class="tab-panel" v-if="loginTabActive == 2">
                            <login-by-phone @submit="loginSuccess" @register="goRegister"></login-by-phone>
                        </div>

                    </div>
                    <div class="register-wrap" :style="{'transform': routeStep == 'register' ? 'translateX(0%)' : 'translateX(100%)'}"> 
                        <register @goback="goLogin"></register>    
                    </div>
                </div>
            </div>
        </div>
        <div class="login-footer"></div>
    </div>
</template>
<script lang="ts" setup>
import {ref, reactive} from 'vue';
import { ElMessage } from 'element-plus'
import loginByAccount from './component/loginByAccount'
import loginByPhone from './component/loginByPhone'
import register from './component/register'
import cookies from 'libs/cookies'

import { useRouter } from 'vue-router'

const router = useRouter();

const routeStep = ref('login')

const loginTabList = ref([{
    value:1,
    name:'账号密码登录'
},
// {
//     value:2,
//     name:'手机验证码登录'
// }
])
const loginTabActive = ref(1)


const loginTabClick = (val:number) => {
    loginTabActive.value = val
}

const loginSuccess = (token:string) => {
    cookies.set('token', token)
    router.push({
        path:'/dashboard'
    })
    ElMessage({
        message:'登录成功',
        type:'success'
    })
}

const goRegister = () => {
    routeStep.value = 'register'
}

const goLogin = () => {
    routeStep.value = 'login'
}

</script>
<style lang="scss" scoped>
.login-page{
    width: 100%;
    height: 100%;
    background-color: #F6F9FF;
    display: flex;
    flex-direction: column;

    .login-header{
        height:80px
    }

    .login-body{
        position: relative;
        flex: 1;
        height: 0;

        .content-wrap{
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%,-50%);
            width: 976px;
            height: 640px;
            background: #FFFFFF;
            box-shadow: 0px 0px 40px 0px rgba(0,0,0,0.05);
            border-radius: 16px;
            overflow: hidden;
            display: flex;

            .form-wrap,
            .img-wrap{
                flex: 1;
                height: 100%;
                position: relative;
                overflow: hidden;

                img{
                    width: 100%;
                    height: 100%;
                }
            }
        }
    }

    .img-wrap{
        background-color: #2770EE;
    }

    .login-wrap,
    .register-wrap{
        position: absolute;
        left: 0;
        top:0;
        width: 100%;
        height: 100%;
        transition: all 0.5s;
    }

    .login-wrap{
        .title{
            margin-top: 113px;
            margin-bottom: 40px;
            font-size: 30px;
            font-weight: 600;
            color: #000000;
            line-height: 38px;
            text-align: center;
        }

        .tabs{
            width: 360px;
            height: 40px;
            display: flex;
            margin: 0 auto;

            .tab-item{
                position: relative;
                flex: 1;
                display: flex;
                justify-content: center;
                font-size: 14px;
                color: #c0c4cc;
                cursor: pointer;

                &::before{
                    content:' ';
                    width: 100%;
                    height: 2px;
                    position: absolute;
                    left: 0;
                    bottom: 0;
                    background-color: #f2f5fc;
                }

                &.is-active{
                    color: #2770EE;

                    &::before{
                        background-color: #2770EE;
                    }
                }
            }
        }

        .tab-panel{
            margin: 40px auto 0 auto;
            width: 360px;
        }
    }

    :deep(.login-form) {
        .el-input{
            border-radius: 8px;
        }

        .el-input__wrapper{
            padding: 0 17px;
            .el-input__inner{
                height: 48px;
            }
        }        
    } 

    :deep(.btn){
        height: 48px;
        width: 100%;
        padding: 16px 15px;
        margin-top: 22px;

        &.is-disabled{
            background-color: rgba(0,0,0,0.04);
            border-color: rgba(0,0,0,0.04);
            color: #c0c4cc;
        }
    }
    
    .register-wrap{
        transform: translateX(100%);
    }

    .login-footer{
        height: 80px;
    }
}
</style>